package com.gxan.web.renshi;

import com.alibaba.fastjson.JSONObject;
import com.gxan.pojo.Archives;
import com.gxan.renshiservice.ServiceArchives;
import com.gxan.renshiservice.impl.ServiceArchivesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/archives/search")
public class SearchArchivesServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        //自定义map的java对象
        Map map = new HashMap();
        try{
            String archives_id = req.getParameter("archives_id");
            String audit_status = req.getParameter("audit_status");
            String status = req.getParameter("status");
            String s_date = req.getParameter("s_date");
            String t_date = req.getParameter("t_date");
            System.out.println(status);
            System.out.println("servlet"+archives_id);
            Integer page = 1;
            Integer limit = Integer.valueOf(req.getParameter("limit"));
            ServiceArchives  serviceArchives = new ServiceArchivesImpl();
            List<Archives> list = serviceArchives.searchArchives(archives_id,audit_status,status,s_date,t_date,page,limit);
            map.put("code",0);
            map.put("msg","success");
            map.put("count",serviceArchives.countArchivesByCoundition(archives_id,audit_status,status,s_date,t_date));
            map.put("data",list);
            // 需要将Java对象转换为json字符串对象才能在网络中进行传输
            resp.getWriter().write(JSONObject.toJSONString(map));
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", -1);
            map.put("msg", "系统开小差了，请联系管理员");
            // 需要将Java对象转换为json字符串对象才能在网络中进行传输
            resp.getWriter().write(JSONObject.toJSONString(map));
        }
        resp.getWriter().flush();
        resp.getWriter().close();
        }
    }
